class Solution(object):
    def rotate(self, matrix):
        """
        :type matrix: List[List[int]]
        :rtype: None Do not return anything, modify matrix in-place instead.
        """
        replaced_dict = {}
        n = len(matrix)
        for i in range(n):
            for j in range(n):
                #若被替换过，则从替换的数据里面获取
                if (i,j) in replaced_dict:
                    temp = replaced_dict[(i,j)]
                    del(replaced_dict[(i,j)])
                else:
                    temp = matrix[i][j]
                
                #保留被替换的数
                if j >= i and ((j,n-1-i)) not in replaced_dict:
                    replaced_dict[(j,n-1-i)] = matrix[j][n-1-i]              
                matrix[j][n-1-i] = temp
